package com.zy.thread.bank3;

/**
 * @Author Gong
 * @Description
 * @dATE 2021/12/14 13:06
 **/
public class Customer extends Thread{

    private Account account;
    Customer(Account account){
        this.account = account;
    }
    @Override
    public void run() {

        while (true) {
//            System.out.println(Thread.currentThread().getName()+"进入线程");
            synchronized(this.account){
                this.account.notify();
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                if(account.getMoney() < 10000){
                    account.addMoney(1000);
                }else{
                    break;
                }

                try {
                    this.account.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
